package cn.hx.whh.automaticticket.dialog;


import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

import cn.hx.whh.automaticticket.R;

/**
 * 提示遮罩类
 */
public class TipsDialogView {
    private Dialog dialog;

    private TextView tips;

    private Timer timer;
    private TimerTask task;
    /**
     *
     * @param mActivity
     * @param tips  提示语
     */
    public TipsDialogView(Activity mActivity,String tips) {
        this.dialog = new Dialog(mActivity, R.style.mask_dialog);
        LinearLayout popView = (LinearLayout) LayoutInflater.from(mActivity).inflate(R.layout.tips_dialog_view, null);

        this.dialog.setContentView(popView,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        this.dialog.setFeatureDrawableAlpha(Window.FEATURE_OPTIONS_PANEL, 0);
        this.tips = (TextView) popView.findViewById(R.id.tips);
        this.tips.setText(tips);
        this.timer = new Timer(true);
        this.task = new TimerTask() {
            public void run() {
                switchActivity();
            }
        };
        init();
    }

    private void init() {
        timer.schedule(task, 3000 * 10, 1000 * 60);
    }

    private void switchActivity() {
        hide();
    }

    public void show() {
        dialog.show();
    }

    public void hide() {
        dialog.dismiss();
    }
}
